// pages/order-detail/order-detail.js
import {
	request
  } from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderItemDtos: [],
    remarks: "",
    actualTotal: 0,
    userAddrDto: null,
    orderNumber: "",
    createTime: "",
    status: 0,
    productTotalAmount: '',
    transfee: '',
    reduceAmount: '',
    shopId: '',
    prodid: ''
  },

  toProdPage: function(e) {
    var prodid = e.currentTarget.dataset.prodid;
    wx.navigateTo({
      url: '/pages/prod/prod?prodid=' + prodid,
    })
  },
  addToCart: function(event) {
    let index = event.currentTarget.dataset.index
    var this_ = this;
    request({
      url: "/p/shopCart/changeItem",
      header: {
				'Authorization': "7Jr/9m22Ty+r96r/kyX+ejusJzlakoKY6ZqVdAtPBBOFdSG/emDQUuO7h8151+4/"
			},
      method: "POST",
      data: {
        basketId: 0,
        count: this.data.orderItemDtos[index].prodCount,
        prodId: this.data.orderItemDtos[index].prodId,
        shopId: this.data.shopId,
        skuId: this.data.orderItemDtos[index].skuId
      }
    }).then(res=>{
      // wx.switchTab({
      //   url: '/pages/basket/basket',
      // })
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadOrderDetail(options.orderNum);
  },

  /**
   * 加载订单数据
   */
  loadOrderDetail: function(orderNum) {
    var this_ = this;
    wx.showLoading();
    //加载订单详情
    request({
      url: "/p/myOrder/orderDetail",
      header: {
				'Authorization': "7Jr/9m22Ty+r96r/kyX+ejusJzlakoKY6ZqVdAtPBBOFdSG/emDQUuO7h8151+4/"
			},
      method: "GET",
      data: {
        orderNumber: orderNum
      }
    }).then(res=>{
      this_.setData({
        orderNumber: orderNum,
        actualTotal: res.actualTotal,
        userAddrDto: res.userAddrDto,
        remarks: res.remarks,
        orderItemDtos: res.orderItemDtos,
        createTime: res.createTime,
        status: res.status,
        productTotalAmount: res.orderItemDtos[0].productTotalAmount,
        transfee: res.transfee,
        reduceAmount: res.reduceAmount,
        actualTotal: res.actualTotal,
        shopId: res.shopId
      });
      wx.hideLoading();
    });

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },


  // 复制
  copyBtn: function(e) {
    var this_ = this;
    wx.setClipboardData({
      data: this_.data.orderNumber,
      success: function(res) {
        wx.showToast({
          title: '复制成功',
        });
      }
    })
  },
})